﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CommonUtils;
using TERP.WaterClient.Common;
using TERP.WaterClient.DbServices;

namespace TERP.WaterClient.Views.Water
{
    public partial class FrmWaterStockOutList : FrmMdiBase
    {
        #region Pro

		//ITS.Library.WaterStockOutService.WaterStockOutServiceClient _clientStockOut;

		private const string Field_Amount = "AMOUNT";
		StockOutService _stockOutService;
        #endregion

        #region Method

        void InitControl()
        {
            CusName.FieldName = TblCustomer.CusName;
            StockOutCode.FieldName = TblStockOut.StockOutCode;
			StockOutDate.FieldName = TblStockOut.StockOutDate;
			Note.FieldName = TblStockOut.Note;
			Price.FieldName = TblStockOut.Price;
			PriceCuocVo.FieldName = TblStockOut.PriceCuocVo;
			NoVo.FieldName = TblStockOut.NoVo;
			Quantity.FieldName = TblStockOut.Quantity;
			CuocVo.FieldName = TblStockOut.CuocVo;
			TotalAmount.FieldName = Field_Amount;

            gridView1.OptionsBehavior.Editable = false;

            this.SetGridViewIndexNormal(gridView1);

            //format
            this.SetGridColumnDateFormat(StockOutDate);
        }

        void SearchData()
        {
            try
            {
				_stockOutService = new StockOutService();
				DataSet ds_StockOut=	_stockOutService.Its_StockOut_Get(
													""
													, this.GetDateEditStringValue(dedFromDate, Nonsense.DATE_DB_FORMAT)
													, this.GetDateEditStringValue(dedToDate, Nonsense.DATE_DB_FORMAT)
													, ""
													, ""
													, ""
													, this.GetTextBoxStringValue(txtOrgName)
													);
				DataTable dt_StockOut = ds_StockOut.Tables[DbTable.Tbl_StockOut];
				gridControl1.DataSource = dt_StockOut;
            }
            catch (Exception ex)
            {
                Util.ShowExceptionBox(ex);
            }
        }
        #endregion

        #region Event
        public FrmWaterStockOutList()
        {
            InitializeComponent();

            InitControl();

            dedFromDate.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            dedFromDate.Properties.DisplayFormat.FormatString = Nonsense.DATE_FORMAT;
            dedFromDate.Properties.EditMask = Nonsense.DATE_FORMAT;

            dedToDate.Properties.DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime;
            dedToDate.Properties.DisplayFormat.FormatString = Nonsense.DATE_FORMAT;
            dedToDate.Properties.EditMask = Nonsense.DATE_FORMAT;

            dedFromDate.DateTime = Util.GetDateFirstOfCurrentMonth(DateTime.Now);
            dedToDate.DateTime = Util.GetDateFirstOfCurrentMonth(DateTime.Now).AddMonths(1).AddDays(-1);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnNhapMoi_Click(object sender, EventArgs e)
        {
            FrmCustomer frm = new FrmCustomer();
            frm.ShowDialog();
        }        

        private void btnSearch_Click(object sender, EventArgs e)
        {
            DateTime dtFromDate = dedFromDate.DateTime.Date;
            DateTime dtToDate = dedToDate.DateTime.Date;

            SearchData();
        }

        private void FrmWaterStockOutList_Load(object sender, EventArgs e)
        {
            DateTime dtFromDate = dedFromDate.DateTime.Date;
            DateTime dtToDate = dedToDate.DateTime.Date;

            SearchData();
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            int _SOID = Convert.ToInt32(gridView1.GetFocusedRowCellValue("StockOutID"));
			//FrmWaterStockOut frm = new FrmWaterStockOut();
			//frm.MdiParent = FrmMain.ActiveForm;
			//frm._StockOutID = _SOID;
			//frm.Show();
        }

        #endregion
    }
}
